package com.example.plane.spirit;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;
import com.example.plane.MainActivity;
import com.example.plane.MenuActivity;

import java.util.ArrayList;
import java.util.Timer;
import java.util.TimerTask;
import static java.lang.Thread.sleep;
public class Buttle {
    public ArrayList<Bitmap>  the_buttle =new ArrayList<Bitmap>();
    public ArrayList<Integer>  buttlex =new ArrayList<>();
    public ArrayList<Integer>  buttley =new ArrayList<>();
    public int cx;
    public int cy;
    public Buttle(){};
    public Thread thread;
    public Timer timer=new Timer();
    public long start_time=0;
    public int speed=40;
    public Bitmap bitmap;
    public void set_buttle_position(int x,int y,Bitmap bitmap){
       this.cx=x+bitmap.getWidth()/2;
       this.cy=y;
    }
    public void initView()  {
        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                bitmap= MainActivity.bitmap[2];
                    the_buttle.add(bitmap);
                    buttlex.add(cx);
                   buttley.add(cy);
                    try {
                        if(start_time!=0) {
                            sleep(400-(System.currentTimeMillis()-start_time));
                        }
                        else{
                            sleep(400);
                        }
                    } catch (InterruptedException e) {

                    }
            }
        },0);
        start_time=System.currentTimeMillis();
    }
    public void draw(Canvas canvas){
        Paint p=new Paint();
        for(int i=0;i<the_buttle.size();i++){
            canvas.drawBitmap(the_buttle.get(i), buttlex.get(i), buttley.get(i), p);
        }
    }
    public void logic(){
           for(int i=0;i<the_buttle.size();i++){
               buttley.set(i,buttley.get(i)-speed);

           }
    }
    public void buttle_remove(){
        for(int i=0;i<the_buttle.size();i++) {
            if (buttley.get(i) < 0) {
                the_buttle.remove(i);
                buttley.remove(i);
                buttlex.remove(i);
            }

        }
    }

}
